<template>
	<view>
		<view class="none" v-if="isPage">没有内容</view>
		<view class="shipin-content" v-else>
			<view class="shipin-item" v-for="(item, index) in videoList" :key="index" @click="clickVideo(item,index)">
				<view class="shipin-item-left">
					<image :src="item.img_url" mode="aspectFill"></image>
					<i class="iconfont iconbofang"></i>
				</view>
				<view class="shipin-item-right">
					<view class="shipin-item-title">{{item.title}}</view>
					<view class="shipin-item-time">{{item.readnum > 9999 ? item.readnum/10000+'w':item.readnum}}次观看·{{item.time}}</view>
				</view>
			</view>
			<uni-load-more v-if="videoList.length >= 6" :status="status" :content-text="contentText" />
		</view>
	</view>
</template>

<script>
	import util from '@/common/util.js';
	export default {
		data() {
			return {
				myId: uni.getStorageSync('userInfo').id,
				user_id: '',
				videoList: [],
				page: 1,
				reload: true,
				isPage: false, //是否为空列表
				status: 'more',
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多',
					contentnot: "没数据"
				}
			}
		},
		onNavigationBarButtonTap() {
			uni.navigateTo({
				url: '/pages/school/release'
			})
		},
		onPullDownRefresh() {
			this.page = 1;
			this.reload = true;
			this.isPage = false;
			this.videoList = [];
			this.getVideo();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom() {
			this.status = 'loading';
			this.page = this.page + 1;
			var _this = this;
			setTimeout(function() {
				_this.getVideo();
			}, 500);
		},
		onLoad(e) {
			if (e.user_id) {
				this.user_id = e.user_id;
			} else {
				this.user_id = this.myId;
			}
			if (this.user_id != this.myId) {
				// #ifdef APP-PLUS
				var webView = this.$mp.page.$getAppWebview();
				webView.setTitleNViewButtonStyle(0, {
					width: '0',
					text: ''
				});
				// #endif
			}
		},
		onShow() {
			this.page = 1;
			this.reload = true;
			this.isPage = false;
			this.videoList = [];
			this.getVideo();
		},
		methods: {
			/* 获取作品列表 */
			getVideo() {
				var data = {
					page: this.page,
					pagesize: 8
				}
				var url = ''
				if (this.user_id && this.user_id != this.myId) {
					data.form_id = this.user_id;
					url = 'user/video.Lists/VideoListByForm';
				} else {
					url = 'user/video.Lists/VideoListByOne';
				}
				this.$api.apiPost(url, data).then(res => {
					if (res.data.code == 200) {
						var list = res.data.data.data;
						list.forEach((item) => {
							item.time = util.getLeftTime(item.creat_time);
						})
						this.videoList = this.reload ? list : this.videoList.concat(list);
						this.reload = false;
						this.status = 'more';
					} else {
						this.page = this.page == 1 ? this.page : this.page -= 1
						if (this.reload) {
							this.videoList = [];
							this.isPage = true;
						} else {
							this.status = 'noMore';
						}
					}
				})
			},
			// 播放视频
			clickVideo(item,index) {
				// uni.navigateTo({
				// 	url: '/pages/school/components/web-view?src=' + item.video_url + '&title=' + item.title
				// })
				var type = 3;
				if (this.user_id != this.myId) {
					var type = 2;
				}
				uni.navigateTo({
					url: '/pages/topic/videoDetail?index=' + index + '&pagesize=9&type=' + type + '&user_id=' + this.user_id
				})
			}
		}
	}
</script>

<style lang="scss">
	.none {
		color: #333333;
		font-size: 30upx;
		margin-top: 500upx;
		width: 100%;
		text-align: center;
	}

	.shipin-content {
		padding: 30upx 30upx 100upx;
		width: calc(100% - 60upx);

		.shipin-item {
			display: flex;
			align-content: center;
			height: 160upx;
			margin-bottom: 40upx;

			.shipin-item-left {
				width: 260upx;
				margin-right: 20upx;
				position: relative;

				image {
					width: 100%;
					height: 100%;
					position: absolute;
					border-radius: 10upx;
				}

				i {
					position: absolute;
					z-index: 9;
					color: #FFFFFF;
					font-size: 40px;
					background: #000000;
					opacity: 0.5;
					width: 100%;
					height: 100%;
					border-radius: 10upx;
					display: inline-flex;
					justify-content: center;
					align-items: center;

				}
			}

			.shipin-item-right {
				width: calc(100% - 280upx);
				position: relative;

				.shipin-item-title {
					color: #333333;
					font-size: 30upx;
					white-space: normal;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 3;
					overflow: hidden;
					word-break: break-word;
				}

				.shipin-item-time {
					color: #AAAAAA;
					font-size: 26upx;
					position: absolute;
					bottom: 0;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}
			}
		}
	}
</style>
